/**
 * 
 */
package com.digitalart.futbol.hibernate.daoImpl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.digitalart.futbol.hibernate.dao.CanchaDao;
import com.digitalart.futbol.hibernate.ejb.Cancha;

/**
 * @author Ulises y rambo
 *
 */
@Repository
public class CanchaDaoImpl implements CanchaDao{

	/**
	 * 
	 */
	@Autowired(required=true)
	private SessionFactory sessionFactory;

	@Transactional
	public  Cancha findById(int id){

		String queryString= "from Cancha cancha where cancha.id_cancha=?";

		Cancha result = (Cancha) this.sessionFactory.getCurrentSession().createQuery(queryString).setParameter(0, id).uniqueResult();	

		return result;

	}

	@Transactional
	public Cancha persistOnMerge (Cancha objCancha){
		Cancha result = (Cancha)this.sessionFactory.getCurrentSession().merge(objCancha);

		return result;
	}

	@Transactional
	public List<Cancha> findByAll() {
		String queryString= "from Cancha cancha";

		List<Cancha> result = (List) this.sessionFactory.getCurrentSession().createQuery(queryString).list();	

		return result;

	}

}
